package cn.nfwx.tv.util;

import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.androidadvance.topsnackbar.TSnackbar;

import cn.nfwx.tv.R;

/**
 * Created by dell on 2018/1/17.
 */

public class TSnackbarUtil {

    /**
     * 预约弹屏
     *
     * @param view
     * @param str
     * @param clickListener
     */
    public static void showTSnackbar(View view, String str, View.OnClickListener clickListener) {
        TSnackbar tSnackbar = TSnackbar.make(view, str, TSnackbar.LENGTH_LONG);
        TSnackbar.SnackbarLayout snackbarView = (TSnackbar.SnackbarLayout) tSnackbar.getView();
        snackbarView.setBackgroundColor(Color.parseColor("#CC000000"));
        TextView button = snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_action);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) button.getLayoutParams();
        params.leftMargin = DensityUtil.dip2px(view.getContext(), 38);
        tSnackbar.setDuration(10000);
        tSnackbar.setActionTextColor(Color.WHITE);
        tSnackbar.setAction(R.string.appiontment_look, clickListener);
        button.setBackgroundResource(R.drawable.shape_red_100_bg);
        tSnackbar.show();
    }

    /**
     * 预约弹屏
     *
     * @param view
     * @param str
     * @param clickListener
     */
    public static void showTSnackbar(View view, String str, String actionText, View.OnClickListener clickListener) {
        TSnackbar tSnackbar = TSnackbar.make(view, str, TSnackbar.LENGTH_LONG);
        TSnackbar.SnackbarLayout snackbarView = (TSnackbar.SnackbarLayout) tSnackbar.getView();
        snackbarView.setBackgroundColor(Color.parseColor("#CC000000"));
        TextView button = snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_action);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) button.getLayoutParams();
        params.leftMargin = DensityUtil.dip2px(view.getContext(), 38);
        tSnackbar.setDuration(10000);
        tSnackbar.setActionTextColor(Color.WHITE);
        tSnackbar.setAction(actionText, clickListener);
        button.setBackgroundResource(R.drawable.shape_red_100_bg);
        tSnackbar.show();
    }

    /**
     * 弹出网络提示
     *
     * @param view
     * @param str
     */
    public static void showNetTSnackbar(View view, String str) {
        TSnackbar tSnackbar = TSnackbar.make(view, str, 6000);
        TSnackbar.SnackbarLayout snackbarView = (TSnackbar.SnackbarLayout) tSnackbar.getView();
        snackbarView.setBackgroundColor(Color.parseColor("#55000000"));
        TextView button = snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_action);
        button.setVisibility(View.GONE);
        tSnackbar.show();
    }
}
